<?php

namespace App\Models;
use App\models\sever;
use Illuminate\Database\Eloquent\Model;

class siteconfig extends Model
{
    protected $table = 'siteconfig';
    /**
     * @return mixed
     * 获取所有配置信息
     */
    public static function getConfig(){
         return static::find(1);
    }

    /**
     *  检查网站可访问性
     */
    public static function checkWebsiteConfig(){
         $config = static::getConfig();
         $mess = [
             'sitetite' => $config->sitetitle,
             'keyword'  => $config->metakeyword,
             'desc'     => $config->metadesp
          ];
         if (!$config->count()) {
              $mess['msg'] = '配置信息错误';
              return ['code'=>'400','msg'=>$mess];
         }
         // 判断网站是否维护||或关闭
         if ($config['siteclosed']=='y') {
              $mess['msg'] = $config['closereason'];
              return ['code'=>'400','msg'=>$mess];
         }
         $severconfig = sever::getConfig();

         if ($severconfig->is_update) {
                $isUp = sever::UpdataConfig($severconfig);
                if (!$isUp){
                 return ['code'=>'400','msg'=>"配置文件更新失败"];
                }
         }
         $severconfig->is_update = 0;
         $severconfig->save();
    }
}
